package com.gg.util;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

public class Procuder {
	
	
	
	public static void main(String[] args) throws IOException, TimeoutException {
		
		//1创建ConnectionFactory
		ConnectionFactory connectionFactory = new ConnectionFactory();
		connectionFactory.setHost("127.0.0.1");
		connectionFactory.setPort(5672);
		connectionFactory.setVirtualHost("/");
		//2创建链接
		Connection connection = connectionFactory.newConnection();
		//3创建channel
		Channel channel = connection.createChannel();
		//4通过channel发送数据
		for(int i = 0; i < 5; i++) {
			System.out.println(i);
			String message = i + "Hello RabbitMQ!";
			channel.basicPublish("test002", "test002", null, message.getBytes());
		}
		
		//发完要记得关闭连接
		/*
		 * channel.close(); connection.close();
		 */
	}
}
